import sys
import typing
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5 import QtWidgets

class EnemySpark(QGraphicsItem):
    def __init__(self, scene):
        super(EnemySpark, self).__init__()
        self.root = QFileInfo(__file__).absolutePath()

        self.setVisible(False)

        self.pix = []
        for i in range(6):
            self.pix.append(QPixmap(self.root+"/res/spark"+str(i+1)+".png"))

        self.state = 0

        self.scene = scene
        self.scene.addItem(self)

        self.symbol = False

    def boundingRect(self):
        return QRectF(-self.pix[0].width() * 0.5, -self.pix[0].height() * 0.5, self.pix[0].width(),
                      self.pix[0].height()-16)

    def paint(self, painter: QPainter, option: 'QStyleOptionGraphicsItem', widget: typing.Optional[QWidget] = ...):
        if self.state <= 5:
            painter.drawPixmap(-self.pix[self.state].width()*0.5, -self.pix[self.state].height()*0.5, self.pix[self.state])
            self.state = self.state+1
        else:
            self.symbol = False
            self.setVisible(False)
            self.setPos(QPointF(-300,-300))
    
    def setPos(self, pos: typing.Union[QPointF, QPoint]):
        super(EnemySpark, self).setPos(pos)

    def setRotation(self, angle: float):
        #self.Rotate = angle
        super(EnemySpark, self).setRotation(angle)

    def setVisible(self, visible: bool):
        self.state = 0
        super(EnemySpark, self).setVisible(visible)
        self.update()

    def isVisible(self):
        return super(EnemySpark, self).isVisible()
